<?php
/**********************************************************************************
 *   Copyright(C) 2002 David Stevens
 *
 *   This file is part of OpenBiblio.
 *
 *   OpenBiblio is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   OpenBiblio is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with OpenBiblio; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 **********************************************************************************
 */

  $tab = "rebajas";
  $nav = "none";
  $focus_form_name = "barcodesearch";
  $focus_form_field = "barcodeNmbr";

  require_once("../shared/common.php");
  require_once("../functions/inputFuncs.php");
  require_once("../functions/formatFuncs.php");
  require_once("../shared/logincheck.php");
  require_once("../classes/Member.php");
  require_once("../classes/MemberQuery.php");
  require_once("../classes/BiblioSearch.php");
  require_once("../classes/BiblioSearchQuery.php");
  require_once("../classes/BiblioHold.php");
  require_once("../classes/BiblioHoldQuery.php");
  require_once("../classes/MemberAccountQuery.php");
  require_once("../classes/BiblioStatusHistQuery.php");
  require_once("../classes/DmQuery.php");
  require_once("../shared/get_form_vars.php");
  require_once("../classes/Localize.php");
  //agregado Horacio Alvarez 01-04-06
  require_once("../classes/StaffQuery.php");
  require_once("../classes/MemberSancionHist.php");
  require_once("../classes/MemberSancionHistQuery.php");  
  $loc = new Localize(OBIB_LOCALE,"rebajas");
  
  ?>
  
  <script language="JavaScript">
  function chekearRetraso(accion)
  {
//  var atrasado=document.barcodesearch.atrasado.value;
  var atrasado=window.document.getElementById("atrasado").value;
  if(accion=="prestamo")
     {
     if(atrasado!=1)
       popSecondary('elegir_tipo_prestamo.php','400','330');
	 else
	   alert("Este socio esta retrasado, no puede extraer libros");
	 }
  if(accion=="reserva")
    {
     if(atrasado!=1)
       window.document.holdForm.submit();
	 else
	   alert("Este socio esta retrasado, no puede reservar libros");	 
	}
  }
  
  function chekearRetrasoParaPrestarReservado(bibid,copyid,holdid,mbrid)
  {
  var atrasado=window.document.getElementById("atrasado").value;
     if(atrasado!=1)
       window.location.replace("../shared/hold_del.php?bibid="+bibid+"&copyid="+copyid+"&holdid="+holdid+"&mbrid="+mbrid+"&prestar=yes");
	 else
	   alert("Este socio esta retrasado, no puede reservar libros");	 
  }
  </script>
  
  <?

  #****************************************************************************
  #*  Checking for get vars.  Go back to form if none found.
  #****************************************************************************
  if (count($_GET) == 0) {
    header("Location: ../circ/index.php");
    exit();
  }

  #****************************************************************************
  #*  Retrieving get var
  #****************************************************************************
  $mbrid = $_GET["mbrid"];
  if (isset($_GET["msg"])) {
    $msg = "<font class=\"error\">".stripslashes($_GET["msg"])."</font><br><br>";
  } else {
    $msg = "";
  }

  #****************************************************************************
  #*  Loading a few domain tables into associative arrays
  #****************************************************************************
  $dmQ = new DmQuery();
  $dmQ->connect();
  if ($dmQ->errorOccurred()) {
    $dmQ->close();
    displayErrorPage($dmQ);
  }
  /***********************************/
  /*Actualiza las reservas vencidas  */
  /***********************************/
  $dmQ->actualizarReservasVencidas();
  /***********************************/
  /*Fin Actualiza las reservas vencidas  */
  /***********************************/
  $dmQ->execSelect("mbr_classify_dm");
  $mbrClassifyDm = $dmQ->fetchRows();
  $dmQ->execSelect("biblio_status_dm");
  //DOS LINEAS AGREGADAS: Horacio Alvarez FECHA: 25-03-06
  $biblioStatusDm = $dmQ->fetchRows();
  $dmQ->execSelect("biblio_cod_library");
  $biblio_cod_library = $dmQ->fetchRows();    
  $dmQ->execSelect("material_type_dm");
  $materialTypeDm = $dmQ->fetchRows();
  // reseting row to top of same result set to get image_file.  This avoids having to do another select.
  $dmQ->resetResult();
  $materialImageFiles = $dmQ->fetchRows("image_file");
  $dmQ->close();

  #****************************************************************************
  #*  Check for outstanding balance due
  #****************************************************************************
  $acctQ = new MemberAccountQuery();
  $acctQ->connect();
  if ($acctQ->errorOccurred()) {
    $acctQ->close();
    displayErrorPage($acctQ);
  }
  $balance = $acctQ->getBalance($mbrid);
  if ($acctQ->errorOccurred()) {
    $acctQ->close();
    displayErrorPage($acctQ);
  }
  $acctQ->close();
  $balMsg = "";
  if ($balance != 0) {
    $balText = moneyFormat($balance,2);
    $balMsg = "<font class=\"error\">".$loc->getText("mbrViewBalMsg",array("bal"=>$balText))."</font><br><br>";
  }

  #****************************************************************************
  #*  Search database for member
  #****************************************************************************
  $mbrQ = new MemberQuery();
  $mbrQ->connect();
  if ($mbrQ->errorOccurred()) {
    $mbrQ->close();
    displayErrorPage($mbrQ);
  }
  if (!$mbrQ->execSelect($mbrid)) {
    $mbrQ->close();
    displayErrorPage($mbrQ);
  }
  $mbr = $mbrQ->fetchMember();
  $mbrQ->actualizar_infracciones($mbr);
  
  if (!$mbrQ->execSelect($mbrid)) {
    $mbrQ->close();
    displayErrorPage($mbrQ);
  }
  $mbr = $mbrQ->fetchMember();
  
  $mbrQ->actualizar_contadores($mbr);
  
  if (!$mbrQ->execSelect($mbrid)) {
    $mbrQ->close();
    displayErrorPage($mbrQ);
  }
  $mbr = $mbrQ->fetchMember();  
  

  #**************************************************************************
  #*  Show member information
  #**************************************************************************
  require_once("../shared/header.php");
?>

<?php echo $balMsg ?>
<?php echo $msg ?> 
<table class="primary">
  <tr><td class="noborder" valign="top">
  <br>
<table class="primary">
  <tr>
    <th align="left" colspan="4" nowrap="yes">
      <?php print $loc->getText("mbrViewHead1"); ?>
    </th>
  </tr>
  <tr>
    <td class="primary" valign="top">
      <b><?php print $loc->getText("mbrViewCardNmbr"); ?></b>
    </td>
    <td valign="top" class="primary">
      <b><?php echo $mbr->getBarcodeNmbr();?></b>
    </td>
    
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewLimitePrestamos"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $mbr->getLimitePrestamos();?>
    </td>	
  </tr>
  <tr>
    <td nowrap="true" class="primary" valign="top">
      <b><?php print $loc->getText("mbrViewName"); ?></b>
    </td>
    <td valign="top" class="primary">
      <b><?php echo $mbr->getLastName();?>, <?php echo $mbr->getFirstName();?></b>
    </td>
    
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewCantidadPrestamos"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $mbr->getCantidadPrestamos();?>
    </td>	
  </tr>
  <tr>
    
	<td class="primary" valign="top">
      <?php print $loc->getText("mbrViewAddr"); ?>
    </td>
    <td valign="top" class="primary">
      <?php
        if ($mbr->getAddress1() != "") echo $mbr->getAddress1()."<br>\n";
        if ($mbr->getAddress2() != "") echo $mbr->getAddress2()."<br>\n";
        if ($mbr->getCity() != "") {
          echo $mbr->getCity().", ".$mbr->getState()." ".$mbr->getZip();
          if ($mbr->getZipExt() != 0) {
            echo "-".$mbr->getZipExt()."<br>\n";
          } else {
            echo "<br>\n";
          }
        }
      ?>
    </td>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewLimiteReservas"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $mbr->getLimiteReservas();?>
    </td>	
  </tr>
  <!--
  Fila agregada: Horacio Alvarez
  Fecha: 25-03-06
  Descripcion: Muestra el nombre de la biblioteca asignada
  -->
  <tr>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewLibraryid"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $biblio_cod_library[$mbr->getLibraryid()];?>
    </td>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewCantidadReservas"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $mbr->getCantidadReservas();?>
    </td>	
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewClassify"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $mbrClassifyDm[$mbr->getClassification()];?>
    </td>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrFldsSanciones"); ?>
    </td>
    <td valign="top" class="primary">
      <?php printDomainDescription("tipo_sancion_dm",$mbr->getTipo_sancion_cd());
	        if($mbr->getTipo_sancion_cd()>0) echo " al ".$mbr->getInicio_sancionDDmmYYYY();?>
    </td>	
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewPhone"); ?>
    </td>
    <td valign="top" class="primary">
      <?php
        if ($mbr->getHomePhone() != "") {
          echo $loc->getText("mbrViewPhoneHome").$mbr->getHomePhone()." ";
        }
        if ($mbr->getWorkPhone() != "") {
          echo $loc->getText("mbrViewPhoneWork").$mbr->getWorkPhone();
        }
      ?>
    </td>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrFldsObservaciones"); ?>
    </td>
    <td valign="top" class="primary">
      <b> <font color='red'><?php echo $mbr->getObservaciones();?></font><b>
    </td>	
  </tr>
  <tr>
    <td class="primary" valign="top">
      <?php print $loc->getText("mbrViewEmail"); ?>
    </td>
    <td valign="top" class="primary">
      <?php echo $mbr->getEmail();?>
    </td>
  </tr>
</table>

  </td>
  <!--Name: HORACIO ALVAREZ
      Date: 2006-03-15
	  Description: Se comenta esta porcion de codigo.
	               El codigo escribe una tabla que informa que cantidad de libros, 
				   de cada tipo de material que el socio tiene en su poder.
  <td class="noborder" valign="top">

<?php
  #****************************************************************************
  #*  Show checkout stats
  #****************************************************************************
/*  $dmQ = new DmQuery();
  $dmQ->connect();
  if ($dmQ->errorOccurred()) {
    $dmQ->close();
    displayErrorPage($dmQ);
  }
  $dmQ->execCheckoutStats($mbr->getMbrid());
  if ($dmQ->errorOccurred()) {
    $dmQ->close();
    displayErrorPage($dmQ);
  }*/
?>
<?php // print $loc->getText("mbrViewHead2"); ?>
<table class="primary">
  <tr>
    <th align="left">
      <?php // print $loc->getText("mbrViewStatColHdr1"); ?>
    </th>
    <th align="left">
      <?php // print $loc->getText("mbrViewStatColHdr2"); ?>
    </th>
    <th align="left" nowrap="yes">
      <?php // print $loc->getText("mbrViewStatColHdr3"); ?>
    </th>
  </tr>
<?php
//  while ($dm = $dmQ->fetchRow()) {
?>
  <tr>
    <td nowrap="true" class="primary" valign="top">
      <?php // echo $dm->getDescription(); ?>
    </td>
    <td valign="top" class="primary">
      <?php // echo $dm->getCount(); ?>
    </td>
    <td valign="top" class="primary">
      <?php /* if ($mbr->getClassification() == "a") {
        echo $dm->getAdultCheckoutLimit();
      } else {
        echo $dm->getJuvenileCheckoutLimit();
      } */?>
    </td>
  </tr>
<?php
/*  }
  $dmQ->close();*/
?>
  </table>
</td>  
      FIN COMENTARIOS--></tr></table>

<br>
<!--****************************************************************************
    *  Checkout form
    **************************************************************************** -->
<!--
Autor: Horacio Alvarez
Fecha: 22-06-03
Descripcion: Se agrega esta funcion javascript
para atrapar el submit lanzado por la tecla enter
y anularlo.
-->
<script language="JavaScript">
/*document.onkeydown = function(){ 
      if(window.event && window.event.keyCode == 13){
       window.event.keyCode = 505; 
      }
      if(window.event && window.event.keyCode == 505){ 
       return false;    
      } 
   } */
function prestar_event(e)
{
      if(e.keyCode == 13){
	   window.event.keyCode = 505; 
       chekearRetraso('prestamo');
	   return false
      }
}
</script>	



<?php require_once("../shared/footer.php"); ?>
